package com.hspedu.jichu.lingqiantong;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

//零钱通功能
public class LqtDetail {


    public static void main(String[] args) {
        //循环打印零钱通菜单
        boolean loop = true;
        //输入的菜单
        Scanner myScanner = new Scanner(System.in);
        // 1 零钱明细
        double money = 0;//入账或消费金额
        Date date = null;//日期
        double balance = 0;//余额
        String note;
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        String detail = "";
        do{
            System.out.println("-------------零钱通菜单-------------");
            System.out.println("-------------1 零钱明细-------------");
            System.out.println("-------------2 收益入账-------------");
            System.out.println("-------------3 消   费-------------");
            System.out.println("-------------4 退   出-------------");
            System.out.print("请选择(1-4):");
            int key = myScanner.nextInt();
            switch(key){
                case 1:
                    System.out.println("================零钱通明细==============");
                    System.out.print(detail);
                    break;
                case 2:
                    System.out.println("收益入账");
                    date = new Date();

                    //对输入金额校验
                    do{
                        System.out.println("请输入入账金额：");
                        money = myScanner.nextDouble();
                        if (money > 0){
                            break;
                        }
                        System.out.println("输入金额有误");
                    }while (money < 0);
                    balance += money;

                    detail += "\n收益入账 +" + money + "\t" + sdf.format(date) + "\t" + "余额: " + balance + "\n";
                    break;
                case 3:
                    System.out.println("消费");
                    date = new Date();
                    System.out.println("请输入消费项目：");
                    note = myScanner.next();
                    //对消费金额校验
                    do{
                        System.out.println("请输入消费金额：");
                        money = myScanner.nextDouble();
                        if (money >= 0 && money <= balance){
                            break;
                        }
                        System.out.println("输入金额有误");
                    }while (loop);
                    balance -= money;
                    detail += "\n消费：" + note + "\t" + "-" + money + "\t" + sdf.format(date) + "\t" + "余额: " + balance + "\n";
                    break;
                case 4:
                    System.out.println("已退出零钱通");
                    loop = false;
                    break;
                default:
                    System.out.println("输入错误，请重新输入");
                    break;
            }

        }
        while(loop);
    }


}
